package com.gxwz.document.business.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.gxwz.document.business.dao.IuserDao;
import com.gxwz.document.business.entity.User;
import com.gxwz.document.business.service.IuserService;

@SuppressWarnings("unused")
@Service("userService")
public class UserServiceImpl implements IuserService {
	
	@Resource(name = "userDao")
	private IuserDao userDao;
	
	@Override
	public void saveuser(User user) {
		userDao.saveOrUpdate(user);

	}

	@Override
	public List<User> findAll() {
		String hql ="from User";
		return userDao.find(hql);
	}
	public List<User> findByPage(int index, int pageSize){
		String hql = "from User";
		return userDao.findByPage(hql, index, pageSize);
	}
	@Override
	public List<User> findByUserNameAndPassWord(User user) {
		String hql = "from User u where u.userLoginName = ? and u.userPassword = ?";
		return userDao.find(hql, user.getUserLoginName(), user.getUserPassword());
	}

	/**
	 * 用户添加
	 */
	@Override
	public void add(User user) {
		userDao.saveOrUpdate(user);
	}

	@Override
	public void delete(int userId){
		userDao.delete(userDao.findById(User.class, userId));	
	}

	@Override
	public User findById(int userId) {
		return userDao.findById(User.class, userId);
	}

	@Override
	public void update(User user) {
        userDao.saveOrUpdate(user);
		
	}

	@Override
	public int getRowNum() {
		
		return userDao.findAll().size();
	}
	@Override
	public List<User> findByOder(User user, int index, int pageSize) {
		return userDao.findbyOrder(user, index, pageSize);
	}
}
